<template>
  <div class="mainpg">
    <div class="main_spac1">
      <div class="main_white padding10">
        <div class="mainor_form batch-wrap">
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="90px"
            id="form"
          >
            <el-form-item label="时间：" prop="time">
              <el-date-picker
                v-model="time"
                type="daterange"
                class="time220"
                :editable="false"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                :clearable="false"
                :picker-options="dateOption"
                @change="getArticleList"
              />
            </el-form-item>
            <MainFormBtn @reset="reset" @getSearchFor="getArticleList" :loading="listLoading" :showBtn="false">
            </MainFormBtn>
          </el-form>
        </div>
        <div class="main_table mg-t-6">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="list"
            element-loading-text="加载中"
            fit
            highlight-current-row
            :height="borderHeight"
          >
            <el-table-column label="线路" prop="" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                {{ scope.row.line_number }}条
              </template>
            </el-table-column>
            <el-table-column label="车辆" prop="" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                {{ scope.row.car_number }}辆
              </template>
            </el-table-column>
            <el-table-column label="体积" prop="" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                {{ scope.row.volume }}（m³）
              </template>
            </el-table-column>
            <el-table-column label="重量" prop="" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                {{ scope.row.weight }}（t）
              </template>
            </el-table-column>
            <el-table-column
              label="配送日期"
              prop=""
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                {{ parseTime(scope.row.send_time, "{y}-{m}-{d}") }}
              </template>
            </el-table-column>
            <el-table-column
              label="创建时间"
              prop=""
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">
                {{ parseTime(scope.row.created_at, "{y}-{m}-{d}") }}
              </template>
            </el-table-column>
            <el-table-column label="操作" prop="" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <router-link
                  :to="'/distribution/line/history/see/' + scope.row.id"
                >
                  <el-link type="success">查看</el-link>
                </router-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div></div>
          <!-- 分页 -->
          <div class="main_page_r">
            <MainPagination
              :current-page="current.page"
              :page-sizes="[20, 30, 50, 100]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mixins } from "@/mixins/index.js";
import { lineHistory_index } from "@/api/distribution/distributionLinePlan";
import rules from "@/rules/distribution/distributionLine";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";
import dateOption from "@/options/dateOption";

export default {
  mixins: [mixins],
  components: {},
  data() {
    return {
      parseTime,
      dateOption,
      // 增加和编辑
      info: {
        title: "",
      },
      type: 0,
      id: 0,
      addedFormVisible: false,
      // 搜索
      form: {
        start_time: "",
        end_time: "",
      },
      time: [],
      // 验证
      rules,
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: [],
      listLoading: false,
    };
  },
  methods: {
    startGetting() {
      this.getArticleList();
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.lineHistory_index();
    },
    reset() {
      this.$refs["userListFrom"].resetFields();
      this.time = [];
      this.lineHistory_index();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.lineHistory_index();
    },
    changePage(page) {
      this.current.page = page;
      this.lineHistory_index();
    },
    // 列表
    lineHistory_index() {
      this.listLoading = true;
      this.form_list();
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.form_list(),
        this.current
      );
      lineHistory_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.list = res.data.list.data;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    form_list() {
      let form = JSON.parse(JSON.stringify(this.form));
      this.form.start_time = this.time[0] ? this.time[0] : "";
      this.form.end_time = this.time[1] ? this.time[1] : "";
      return form;
    },
  },
  created() {
    // 列表
    this.getNumerical(230);
    this.lineHistory_index();
  },
};
</script>
<style lang="scss" scoped>
.mainor_form form {
  width: calc(100% - 200px);
}
/deep/.el-form-item--small.el-form-item {
  margin-bottom: 10px;
}
</style>
